
package com.rt.schedulenew.service.impl;

import org.apache.shiro.session.Session;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.mgt.SessionKey;
import com.rt.schedulenew.utils.jwt.util.JwtTokenUtil;

import java.io.Serializable;

import com.rt.schedulenew.utils.util.EhCacheUtil;
import com.rt.schedulenew.utils.base.ConstantsUtil;
import org.springframework.stereotype.Service;
import com.rt.schedulenew.api.ISSOService;

@Service
public class SSOImpl implements ISSOService {
    @Override
    public Boolean isLogin(String token) {
        Boolean isExpired = EhCacheUtil.isExpired(ConstantsUtil.EhCacheName.tokenCache.name(), token, (Serializable) token);
        if (isExpired) {
            EhCacheUtil.put(ConstantsUtil.EhCacheName.tokenCache.name(), token, (Serializable) token);
            String sessionId = JwtTokenUtil.getSessionId(token);
            SessionKey sessionKey = () -> sessionId;
            Session session = SecurityUtils.getSecurityManager().getSession(sessionKey);
            if (session != null) {
                session.touch();
            }
        }
        return isExpired;
    }
}
